import game from './game'
import 'pixi.js';
import 'p2';
import Phaser from 'phaser';
import config from './config';
var scoreText;
window.scorecard =[null,null,null];
function create() {
    console.log("创建游戏")
  
    game.physics.startSystem(Phaser.Physics.ARCADE);
   
    game.stage.backgroundColor = '#03A9F4';
    game.world.setBounds(0, 0,config.world.width,config.world.height );
    
      //增加星星
      window.stargroup = game.add.physicsGroup();
      // window.stargroup.enableBody  = true;
    for (var i = 0; i < config.star_number; i++)
    {
      //Phaser.Group.prototype.create = function (x, y, key, frame, exists, index) {

        let star19 = stargroup.create(game.world.randomX, game.world.randomY, 'star');
        // console.log("star19",star19);
        star19.body.setCircle(10);
       
        // game.physics.arcade.enable(star19,false);
        // star19.body.bounce=0;
    }
    // console.log(window.stargroup)

      window.cursors = game.input.keyboard.createCursorKeys();
  
      //todo fps 未找到设置方法

      // 原始缩放 0.80 
      game.camera.scale.x = game.camera.scale.y = config.ratio;

      // 创建玩家小球 
      let sprite = game.add.sprite(500, 500, 'ball');
      // sprite.enableBody =true;
      // 设置 缩放
      sprite.scale.x = sprite.scale.y = 2;      
      // console.log('player',sprite);
      sprite.zom = 2;
      
      game.physics.arcade.enable(sprite);
      // sprite.body.bounce=0;
      window.player= sprite;
      window.player.body.setCircle(30,-15,-15);
      // game.camera.x = game.world.centerX *config.ratio - (config.view.width/2);
      // game.camera.y = game.world.centerY *config.ratio -(config.view.height/2) ;

      console.log(game.world.centerX, game.world.centerY);
      console.log(game);

      // 计分显示 
      window.scorecard[0]=game.add.text(200, 10, "姓名: 张三", { font: "20px", fill: "red" });
      window.scorecard[0].fixedToCamera = true;
      window.scorecard[0].cameraOffset.setTo(500, 10);
      window.scorecard[1]=game.add.text(200, 30, "计分 : 10分", { font: "20px", fill: "red" });
      window.scorecard[1].fixedToCamera = true;
      window.scorecard[1].cameraOffset.setTo(500, 30);
      window.scorecard[2]=game.add.text(200, 50, "吞噬: 10 ", { font: "20px", fill: "red" });
      window.scorecard[2].fixedToCamera = true;
      window.scorecard[2].cameraOffset.setTo(500, 50);
  }
  export default create;